import React from 'react';
import {inject, observer} from 'mobx-react';

import PersonTree from '../../../public/persontree/PersonTree';
@inject ('planViewStore')
@observer
export default class LeftCom extends React.Component {
  constructor (props) {
    super (props);
    this.state = {};
    this.store = this.props.planViewStore;
  }

  onNodeSelect = (e, ids, selectedKeys, nodes) => {
    if (selectedKeys && selectedKeys.length > 0) {
      let type = parseInt (selectedKeys[0].split ('__')[0]) + 1;
      let id = selectedKeys[0].split ('__')[1];
      if (type == 4) {
        this.store.resourceid = id;
        this.store.resourcetype = type;
        this.store.getPlanView ();
        this.store.resetTabKey()
      }
    }
  };

  onPersonClick = (id, name) => {
    this.store.resourceid = id;
    this.store.resourcename = name;
    this.store.resourcetype = 4;
    this.store.getPlanView ();
    this.store.resetTabKey()
  };

  render () {
    return (
      <PersonTree ecId={`${this && this.props && this.props.ecId || ''}_PersonTree@ufqtt0`}
        minusHeight={30}
        onPersonClick={this.onPersonClick}
        treeNodeClick={this.onNodeSelect}
      />
    );
  }
}
